<template>
  <van-nav-bar
    fixed
    :left-arrow="leftArrow"
    @click-left="onClickLeft"
    :title="title"
    :right-text="rightText"
    @click-right="emits('click-right')"
  >
    <template #right>
      <slot name="right"></slot>
    </template>
  </van-nav-bar>
</template>
<script setup lang="ts">
import { useRouter } from 'vue-router'

const props = defineProps<{
  leftArrow?: boolean
  title?: string
  rightText?: string
  back?: () => void
}>()
const emits = defineEmits<{
  (e: 'click-right'): void
}>()
const router = useRouter()
const onClickLeft = () => {
  if (props.back) return props.back()
  if (history.state?.back) {
    router.back()
  } else {
    router.push('/')
  }
}
</script>
<style lang="scss" scoped>
:deep() {
  .van-nav-bar {
    &__arrow {
      color: var(--cp-text1);
      font-size: 18px;
    }
    &__title {
      font-size: 15px;
    }
  }
}
</style>
